using System;
using System.Collections.Generic;
using System.Text;
using AllegNet;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace DemonHunter
{
    /// <summary>
    /// background bitmap index
    /// 0 = desert
    /// 1 = barrens
    /// 2 = outskirts
    /// 3 = wall
    /// </summary>

    class Level
    {
        // bitmaps should have a NonSerialized attribute since we will be constantly changing graphics
        private Bmp roadBitmap;
        private Bmp[] backgroundBitmaps;
        private int backgroundIndex;
        private List<Entity> entityList;
        private List<Entity> propList;
        private static Level me;

        public Level()
        {
            me = this;
            LoadBitmaps();
        }

        /// <summary>
        /// load the bitmaps the level will use into memory (in levelBitmaps array)
        /// </summary>
        private void LoadBitmaps()
        {
            //initialize
            entityList = new List<Entity>();
            propList = new List<Entity>();
            Game game = Game.GetInstance();
            backgroundBitmaps = new Bmp[4];

            //create player entity and put it in list
            entityList.Add(new PlayerCharacter());

            //load level backgrounds
            roadBitmap = game.LoadBitmap("C:\\DemonHunterart\\desert\\road.bmp");
            backgroundBitmaps[0] = game.LoadBitmap("C:\\DemonHunterart\\desert\\desertBackground.bmp");
            backgroundBitmaps[1] = game.LoadBitmap("C:\\DemonHunterart\\barrens\\barrensBackground.bmp");
            backgroundBitmaps[2] = game.LoadBitmap("C:\\DemonHunterart\\outskirt\\outskirts.bmp");
            backgroundBitmaps[3] = game.LoadBitmap("C:\\DemonHunterart\\wall\\wall.bmp");
            //load entity bitmaps
            PlayerCharacter.LoadBitmaps();
            Minotaur.LoadBitmaps();
            Skeleton.LoadBitmaps();
            LightneningBolt.LoadBitmaps();
            BackgroundCows.LoadBitmaps();
            Grenade.LoadBitmaps();
            BikerDemon.LoadBitmaps();
            Explosion.LoadBitmaps();
            Portal.LoadBitmaps();
        }

        public static Level GetInstance() { return me; }

        public Bmp GetRoadBitmap() { return roadBitmap; }
        public PlayerCharacter getPlayerChar() { return (PlayerCharacter)entityList[0]; }
        public Entity GetEntity(int idx) { return entityList[idx]; }
        public void AddEntity(Entity e) {  entityList.Add(e); }
        public int GetNumEntities() { return entityList.Count; }
        public Bmp GetBackgroundBitmap() { return backgroundBitmaps[backgroundIndex]; }
        public void RemoveEntity(int idx) { entityList.RemoveAt(idx); }
        public void RemoveEntity(Entity e) { entityList.Remove(e); }
        public int GetBackgroundIndex() { return backgroundIndex; }
        public void SetBackgroundIndex(int idx) { backgroundIndex = idx; }
    }
}
